package com.yulan.xunfei;

import org.junit.Test;

import java.util.Scanner;

public class test1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextInt()) {// 注意，如果输入是多个测试用例，请通过while循环处理多个测试用例
            int[] arr = new int[5];
            for(int i=0; i<5; i++){
                arr[i] = in.nextInt();
            }
            int k = in.nextInt();
            System.out.println(mostNum(arr,k));
        }
    }

    public static int mostNum(int[] arr , int k){
        int sum = arr[0] + arr[1] * 5 + arr[2] * 10 + arr[3] * 50 + arr[4] * 100;
        if(k > sum || k < 0) return  -1;
        int count = 0;
        while(arr[4] > 0 && k >= 100){
            k -= 100;
            arr[4] --;
            count++;
        }
        while(arr[3] > 0 && k >= 50){
            k -= 50;
            arr[3] --;
            count++;
        }
        while(arr[2] > 0 && k >= 10){
            k -= 10;
            arr[2] --;
            count++;
        }
        while(arr[1] > 0 && k >= 5){
            k -= 5;
            arr[1] --;
            count++;
        }
        while(arr[0] > 0 && k >= 1){
            k -= 1;
            arr[0] --;
            count++;
        }
        return k == 0 ? count : -1;
    }

    @Test
    public void test(){
        int[] arr = {1,1,2,3,5};
        System.out.println(mostNum(arr,67));
    }
}
